<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/component.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/normalize.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/css/jquery-ui-timepicker-addon.min.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.7.1.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.core.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.widget.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.position.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.autocomplete.min.js"></script> 
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.7.1.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-addon.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-zh-CN.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>	    
<style>
.overflow-y td,.overflow-y th{
font-size: 12px;
min-width: 150px;
text-align: center;
}
.forhide{ 
 display:none; 
} 
.mypage{display: none;}
.mypage .num{color: red;}
.form-horizontal .control-label{ width:80px;}
.form-horizontal .controls{ margin-left:90px;}
</style>
<script type="text/javascript">
//ajax 请求数据
url='';
page=0;
pagenum=100;
flag=false;
function get_pandian(url,method){
	var dialog = art.dialog({title: '提示',icon:'question',lock: true});
	dialog.content('<p>数据查询中,请稍后...<p>');
	$.get(
    	    url,
    	    {
    	    	sku: $.trim($(".form-horizontal input[name='sku']").val()),
    	    	supplier:$.trim($(".form-horizontal input[name='supplier']").val()),
    	    	per_page: page,
	    	    sortcondition: $(".form-horizontal select[name='sortcondition']").val(),
	    	    order: $(".form-horizontal select[name='order']").val(),
	    	    group: $(".form-horizontal select[name='group']").val(),
	    	    start_time: $(".form-horizontal input[name='start_time']").val(),
	    	    end_time: $(".form-horizontal input[name='end_time']").val(),
	    	 },
	    	  function(data){
		    	  if(method=='search'){
		    		   $('#table_content').empty();
		    		   page=1;
			       }
	    		    $(data).appendTo('#table_content');
	    			var key=parseInt($("select[name='group']").val());
					if(key==1){
		    	        $('#table_content .hidesp').hide();
		    	        $('#table_content .hideprice').hide();
	    	    	}
	    	    	if(key==2){
	    	    		$('#table_content .hidesku').hide();
	    	    		$('#table_content .hideprice').hide();
		    	    }
	    	    	$('#pager_links').empty();
	    	        $($('.mypage').get(0)).clone().appendTo('#pager_links').show();
	    	        $('#table_content .remove').remove();
	    		dialog.close();
	   	   }
    	 );
}
//var availableTags='';
$(function() {
	              var startDateTextBox = $('#start');
	              var endDateTextBox = $('#end');
	              startDateTextBox.datetimepicker({ 
	            	    dateFormat: 'yy-mm-dd',
	            	    timeFormat: 'HH:mm:ss',
	            		onClose: function(dateText, inst) {
	            			if (endDateTextBox.val() != '') {
	            				var testStartDate = startDateTextBox.datetimepicker('getDate');
	            				var testEndDate = endDateTextBox.datetimepicker('getDate');
	            				if (testStartDate > testEndDate)
	            					endDateTextBox.datetimepicker('setDate', testStartDate);
	            			}
	            			else {
	            				endDateTextBox.val(dateText);
	            			}
	            		},
	            		onSelect: function (selectedDateTime){
	            			endDateTextBox.datetimepicker('option', 'minDate', startDateTextBox.datetimepicker('getDate') );
	            		}
	            	});
	            	endDateTextBox.datetimepicker({ 
	            		dateFormat: 'yy-mm-dd', 
   	            		timeFormat: 'HH:mm:ss',
	            		onClose: function(dateText, inst) {
	            			if (startDateTextBox.val() != '') {
	            				var testStartDate = startDateTextBox.datetimepicker('getDate');
	            				var testEndDate = endDateTextBox.datetimepicker('getDate');
	            				if (testStartDate > testEndDate)
	            					startDateTextBox.datetimepicker('setDate', testEndDate);
	            			}
	            			else {
	            				startDateTextBox.val(dateText);
	            			}
	            		},
	            		onSelect: function (selectedDateTime){
	            			startDateTextBox.datetimepicker('option', 'maxDate', endDateTextBox.datetimepicker('getDate') );
	            		}
	            	});
	            	        $( "#search1" ).autocomplete(
							{     
								source:'<?php echo URL::base() ?>inventory/deliverycheck/check_allsupp'
							});
							$("#search").click(function(){
								    flag=true;
								    page++;
   							        url='<?php echo URL::base() ?>inventory/report/in_count_search';
									get_pandian(url,$(this).attr('id'));
								
								});
							$("#load").click(function(){
								var num=$('#pager_links .num').text();
								page++;
				                if(flag){
				                	if(num<(page-1)*pagenum){
										var dialog = art.dialog({title: '提示',icon:'question',lock: true});
										dialog.content('<p>数据已经加载完成<p>');
									}else{
									    url='<?php echo URL::base() ?>inventory/report/in_count_search?page='+page;
										get_pandian(url,$(this).attr('id'));
										}
									}
							});

							
							$("#down").click(function(){
								var num=$('#pager_links .num').text();
							    if(num>5000){
							    	var dialog = art.dialog({title: '提示',icon:'question',lock: true});
							    	dialog.content('<p>你下载的量超过5000条，请加大筛选条件力度<p>');
							    	return;
							    }
							   var sku= $.trim($(".form-horizontal input[name='sku']").val());
							   var sortcondition= $(".form-horizontal select[name='sortcondition']").val();
							   var order= $(".form-horizontal select[name='order']").val();
							   var group=$(".form-horizontal select[name='group']").val();
							   var supplier= $.trim($(".form-horizontal input[name='supplier']").val());
							   var start_time= $(".form-horizontal input[name='start_time']").val();
							   var end_time= $(".form-horizontal input[name='end_time']").val();
							   var uri=url.split('?')[1];
								if(!uri){
									uri='sku='+sku+'&sortcondition='+sortcondition+'&order='+order+'&start_time='+start_time+'&end_time='+end_time+'&group='+group+'&supplier='+supplier;
								}
								window.location.href="<?php echo URL::base()?>inventory/report/down_in_count?"+uri;
							});

							
							
							$("select[name='group']").change(function(){
								$('#table_content').empty();
								flag=false;
								$("td:hidden").show();
								$("th:hidden").show();
							     var key=parseInt($(this).val());
							     $('#sku').hide();
						       	 $('#supplier').hide();
						     	if(key==1){
					    	        $('th:eq(0)').hide();
					    	        $('th:eq(5)').hide();
				    	    	}
				    	    	if(key==2){
				    	    		$('th:eq(1)').hide();
				    	    		$('th:eq(2)').hide();
				    	    		$('th:eq(3)').hide();
				    	    		$('th:eq(5)').hide();
					    	    }
							     switch(key)
							     {
							     case 1:
							 	    $(".form-horizontal input[name='supplier']").val('');
							    	$('#sku').show();
							       break;
							     case 2:
							    	 $(".form-horizontal input[name='sku']").val('');
							    	 $('#supplier').show();
							       break;
							     case 3:
							      	  $('#sku').show();
							       	  $('#supplier').show();
							        break;
							     default:
							     }
							});
        });
</script>
<div class="row" style="margin-top: 25px;">
		<div class="span11">
			<form class="form-horizontal" >
    	      	<div class="control-group " id="sku">
    	      		<label class="control-label w-label">SKU:</label>
					<div class="controls">
						<input type="text"  name='sku' value=""> 
					</div>
				</div>
				<div class="control-group " id="supplier">
    	      		<label class="control-label w-label">供应商:</label>
					<div class="controls">
						<input type="text"  name='supplier' value="" id='search1'> 
					</div>
				</div>
				<div class="control-group">
					<label class="control-label w-label">分组方式:</label>
					<div class="controls">
						<select name='group' >
						    <option value='3'>SKU+供应商</option>
						    <option value='1'>SKU</option>
							<option value='2'>供应商</option>
						</select>
					
					</div>
				</div>
				<div class="control-group">
					<label class="control-label w-label">排序条件</label>
					<div class="controls">
						<select  name='sortcondition'>
							<option value="1">选择（默认SKU）</option>
							<option value='1'>SKU</option>
							<!-- <option value='2'>单价</option> -->
							<option value='3'>金额</option>
							<option value='4'>成本</option>
							<option value='5'>入库量</option>
						</select>
					</div>
				</div>
					<div class="control-group">
					<label class="control-label w-label">排序方式</label>
					<div class="controls">
						<select name='order' >
						    <option value='2'>降序</option>
							<option value='1'>升序</option>
						</select>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label w-label" for="inputPassword">入库日期</label>
					<div class="controls ">
						<input type="text" name='start_time' id="start" readonly="readonly">&nbsp;--&nbsp;<input type="text" name='end_time' id="end" readonly="readonly" >
					    
					    <div style="margin-left:15px;" class="btn btn-success" id='down'><a style="color:#FFF" >下载</a></div>（一次限下载5000条）
					</div>
					<div style="margin-top:15px;margin-left:110px;">
						<div class="btn btn-info" id="search">查询</div>
						<input type="reset" style="margin-left:5px;" class="btn btn-inverse" value="重置">
					</div>
				</div>
			</form>
			<table class="sticky-wrap overflow-y">
              <thead>
                <tr>
                  <th>供应商</th>
                  <th>SKU</th>
                  <th>中文名称</th>
                  <th>储位</th>
                  <th>入库量</th>
                  <th>平均单价</th>
                  <th>金额</th>
                  <th>成本</th>
                </tr>
              </thead>
              <tbody id='table_content'>
              </tbody>
            </table>
            <div id="pager_links"></div>
		</div>
		<div class="span2"></div>
	</div>
<div class="btn btn-success" id='load'><a style="color:#FFF" >继续加载100条</a></div>	
<script src="<?php echo URL::base() ?>media/vendor/fixtable/js/jquery.ba-throttle-debounce.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/fixtable/js/jquery.stickyheader.js"></script>
